package com.tuanzi.loan.web.bean.statistics;

import com.base.common.log.LogService;
import com.google.common.collect.Lists;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.statistics.RegisterNumStatRequest;
import com.tuanzi.loan.vo.response.statistics.RegisterNumStatResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.statistics.RegisterNumStatLazyDataModel;
import com.tuanzi.server.loan_base.util.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
* @Description:    统计comm_user表中分时注册数
* @Author:         xionghao
* @CreateDate:     2019/1/4
*/
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class RegisterNumStatBean extends JSFListingBean<RegisterNumStatRequest,RegisterNumStatResponse>{
    private List<String> channelList = Lists.newArrayList();
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    private void initLazyDataModel() {
        $ = new RegisterNumStatRequest();
        try {
            $.setStartDate(sdf.parse(DateUtils.getDateBeforeDays(1)));
            $.setEndDate(sdf.parse(DateUtils.getCurrentDate()));
        } catch (ParseException e) {
            LogService.error("日期转换异常",e);
        }

        channelList.add("9999");
        $.setChannel(channelList);
        lazyDataModel = new RegisterNumStatLazyDataModel($);
    }

    public String translateProductChannel(String channel){
        if(StringUtils.isNotBlank(channel) && !"空渠道".equals(channel) && !"全部".equals(channel)){
            return translateProductChannel(Integer.parseInt(channel));
        }else{
            return channel;
        }

    }
}
